#!/bin/bash
HOST_QT_PATH=/opt/Qt/5.15.2/gcc_64
mqtt_src_path=~/Mqtt

do_prepare_install () {
sudo apt install libgl1-mesa-dev libxcb-cursor0 -y
export PATH=$PATH:${HOST_QT_PATH}/bin
echo export QT_QPA_PLATFORM=wayland >> ~/.bashrc
echo export LD_LIBRARY_PATH=${HOST_QT_PATH}/lib >> ~/.bashrc
source ~/.bashrc
}

# ver5.15.2 
do_make_host_mqtt5 () {

 echo -e "\033[1;33mstart make and install Mqtt ...\033[0m"
if [ ! -d "${mqtt_src_path}" ];then
     mkdir ${mqtt_src_path}
fi 
cd ${mqtt_src_path}
 
if [ ! -f "v5.15.2.tar.gz" ];then
     wget https://github.com/qt/qtmqtt/archive/refs/tags/v5.15.2.tar.gz
fi 

if [ ! -d "qtmqtt-5.15.2" ];then
   tar -xf v5.15.2.tar.gz
fi 

cd qtmqtt-5.15.2
mkdir ${HOST_QT_PATH}/include/QtMqtt
cp ./src/mqtt/*.h ${HOST_QT_PATH}/include/QtMqtt
${HOST_QT_PATH}/bin/qmake  
make -j6
make install 

 echo -e "\033[1;33m Mqtt done...\033[0m"
}

 
do_prepare_install
do_make_host_mqtt5
 

 
